package com.mlizhi.modules.spec.dao;


import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import com.mlizhi.base.dao.AbstractDao;
import com.mlizhi.base.dao.Property;
import com.mlizhi.base.dao.internal.DaoConfig;
import com.mlizhi.modules.spec.dao.model.DetectModel;



public class DetectDao  extends AbstractDao<DetectModel, Long>{

	public static final String TABLENAME = "DETECT_MODEL";

    /**
     * Properties of entity Note.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property PartType = new Property(1, Integer.class, "partType", true, "PART_TYPE");
        public final static Property DetectType = new Property(2, Integer.class, "detectType", true, "DETECT_TYPE");
        public final static Property NurserType = new Property(3, Integer.class, "nurserType", true, "NURSER_TYPE");
        public final static Property  DetectValue= new Property(4, Double.class, "detectValue", false, "DETECT_VALUE");
        public final static Property UserId = new Property(5, String.class, "userId", false, "USER_ID");
        public final static Property InsertTime = new Property(6, java.util.Date.class, "insertTime", false, "INSERT_TIME");
    };

    public DetectDao(DaoConfig config) {
        super(config);
    }
    
    public DetectDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "'DETECT_MODEL' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'PART_TYPE' INTEGER ," + // 1: partType
                "'DETECT_TYPE' INTEGER ," + // 2: detectType
                "'NURSER_TYPE' INTEGER ," + // 3: nurserType
                "'DETECT_VALUE' DOUBLE ," + // 4: detectValue
                "'USER_ID' TEXT NOT NULL ," + // 5: userId
                "'INSERT_TIME' INTEGER);"); // 6: insertTime
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'DETECT_MODEL'";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, DetectModel entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);//id
        }
        stmt.bindLong(2, entity.getPartType());//partType
        stmt.bindLong(3, entity.getDetectType());//detectType
        stmt.bindLong(4, entity.getNurserType());//nurserType
        stmt.bindDouble(5, entity.getDetectValue());//detectValue
        stmt.bindString(6, entity.getUserId());//userId
        java.util.Date date = entity.getInsertTime();//insertTime
        if (date != null) {
            stmt.bindLong(7, date.getTime());
        }
    }

    /** @inheritdoc */
    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    
    /** @inheritdoc */
    @Override
    public DetectModel readEntity(Cursor cursor, int offset) {
    	DetectModel entity = new DetectModel(
            cursor.isNull(offset + 0) ? -1 : cursor.getLong(offset + 0),//id
            cursor.isNull(offset + 1) ? -1 : cursor.getInt(offset + 1),//partType
            cursor.isNull(offset + 2) ? -1 : cursor.getInt(offset + 2),//detectType
            cursor.isNull(offset + 3) ? -1 : cursor.getInt(offset + 3),//nurserType
            cursor.isNull(offset + 4) ? -1d : cursor.getDouble(offset + 4),//detectValue
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5),//userId
            cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6))//insertTime
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, DetectModel entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setPartType(cursor.isNull(offset + 1) ? -1 : cursor.getInt(offset + 1));
        entity.setDetectType(cursor.isNull(offset + 2) ? -1 : cursor.getInt(offset + 2));
        entity.setNurserType(cursor.isNull(offset + 3) ? -1 : cursor.getInt(offset + 3));
        entity.setDetectValue(cursor.isNull(offset + 4) ? -1d : cursor.getDouble(offset + 4));
        entity.setUserId(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setInsertTime(cursor.isNull(offset + 6) ? null : new java.util.Date(cursor.getLong(offset + 6)));
        
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(DetectModel entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(DetectModel entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
	
}
